﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Import Namespace="AgriMarketWebProj.AgriMarketService" %>
<%@ Import Namespace="AgriMarketWebProj.Models" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>
<script src='../../Scripts/AgriProj/Auction/AddNewBuyAuction.js' type='text/javascript'></script>
    <div id='AddNewBuyAuctionDiv'>
        <div id='ErrorPanelAddNewBuyAuctionDiv' ></div>
        <div id='topicAddNewBuyAuction' style='background-color:#CCCCCC; height:50px; width:100%; '><input id='topicAddNewBuyAuctionInput' type='text' placeholder='Chu de' /></div>
        <div style='background-color:#000000;height:200px; width:600px;'>
            <div  id='pictureAddNewBuyAuctionDiv' style='background-color:#00CC99; width:200px; height:200px; float:left'>
            <img id= 'pictureAddNewBuyAuction'   style='width:200px; height:200px' src='../../Content/TempProductImage.jpg' />
        </div>
            <div id='infoAddNewBuyAuction' style='background-color:#999999; height:200px; width:400px; float:left'>
                <table border='1' style='width:400px; height:auto'>
            </tr>
            <tr style='height:auto'>
                <td>ngay bat dau</td>
                <td id='startedDateAddNewBuyAuction' ><input id='startedDateAddNewBuyAuctionInput'  type='text' />
                    <img src='../../External/DatetimePicker/images2/cal.gif' onclick='javascript:NewCssCal(&apos;startedDateAddNewBuyAuctionInput&apos;,&apos;&apos;,&apos;ddMMyyyy&apos;,&apos;dropdown&apos;,true,&apos;12&apos;,true)' style='cursor:pointer'/>
                </td>
            </tr>
            <tr style='height:auto'>
                <td>ngay ket thuc</td>
                <td id='finishedDateAddNewBuyAuction'><input id='finishedDateAddNewBuyAuctionInput'  type='text' />
                    <img src='../../External/DatetimePicker/images2/cal.gif' onclick='javascript:NewCssCal(&apos;finishedDateAddNewBuyAuctionInput&apos;,&apos;&apos;,&apos;ddMMyyyy&apos;,&apos;dropdown&apos;,true,&apos;12&apos;,true)' style='cursor:pointer'/>
                </td>
            </tr>
            <tr style='height:auto'>
                <td>ten san pham</td>
                <td id='productNameAddNewBuyAuction'>
                    <select id='productAddNewBuyAuctionSelection'>
                        <%
                            List<Product> allProducts = Model;
                            foreach (var product in allProducts)
                            {
                                Response.Write("<option value='" + product.ProductId + "'>" + product.ProductName + "</option>");
                            }                            
                             %>
                    </select>
                </td>
            </tr>
            <tr style='height:auto'>
                <td>gia khoi diem</td>
                <td id='initialPriceAddNewBuyAuction' ><input type='number' placeholder='Giá khởi điểm' value='0' id='initialPriceAddNewBuyAuctionInput' min='0'/></td>
            </tr>

            <tr style='height:auto'>
                <td colspan='2' >
                    <form method='post' id='imageAddNewBuyAuctionForm' name='' action='/Auction/AddNewBuyAuction' enctype='multipart/form-data'>
                        <input type='file' name='imageAddNewBuyAuctionInput' id='imageAddNewBuyAuctionInput' />
                        <input type='hidden' name='topicAddNewBuyAuctionInputHidden' id='topicAddNewBuyAuctionInputHidden' />
                        <input type='hidden' name='startedDateAddNewBuyAuctionInputHidden' id='startedDateAddNewBuyAuctionInputHidden' />
                        <input type='hidden' name='finishedDateAddNewBuyAuctionInputHidden' id='finishedDateAddNewBuyAuctionInputHidden' />
                        <input type='hidden' name='initialPriceAddNewBuyAuctionInputHidden' id='initialPriceAddNewBuyAuctionInputHidden' />
                        <input type='hidden' name='productAddNewBuyAuctionSelectionHidden' id='productAddNewBuyAuctionSelectionHidden' />
                        <input type='hidden' name='productDescriptionAddNewBuyAuctionInputHidden' id='productDescriptionAddNewBuyAuctionInputHidden' />
                        <%                       
                            Response.Write("<input type='hidden' name='currUserAccNameInputHidden' id='currUserAccNameInputHidden' value='" + (string)ViewData["currentUserAccountName"] + "' />");%>
                        
<%--                        <input type='submit' value='SaveImage' />--%>
                    </form>  
                    <%
                        int typeView =int.Parse( ViewData["TypeView"].ToString());
                      if (typeView == 1)
                      {
                      %>
                    <script>
                                    
                    (function () {
                        $('#imageAddNewBuyAuctionForm').ajaxForm({
                            beforeSend: function () {
                            },
                            uploadProgress: function (event, position, total, percentComplete) {
                            },
                            success: function () {
                            },
                            complete: function (xhr) {
                                var data = eval("(" + xhr.responseText + ")");
                                if (data.isOK == -1) {
                                    $('#ErrorPanelAddNewBuyAuctionDiv').html(data.Message);
                                } else {
                                    $('#ErrorPanelAddNewBuyAuctionDiv').html("Thành công");
                                    $("#auctionListDiv").html(data.Content + $("#auctionListDiv").html());
                                }
                            }
                        });

                    })();       
                    </script>    
                    <%}
                      else if (typeView == 2)
                      { %>             
                      <script>

                          (function () {
                              $('#imageAddNewBuyAuctionForm').ajaxForm({
                                  beforeSend: function () {
                                  },
                                  uploadProgress: function (event, position, total, percentComplete) {
                                  },
                                  success: function () {
                                  },
                                  complete: function (xhr) {
                                      var data = eval("(" + xhr.responseText + ")");
                                      if (data.isOK == -1) {
                                          $('#ErrorPanelAddNewBuyAuctionDiv').html(data.Message);
                                      } else {
                                          $('#ErrorPanelAddNewBuyAuctionDiv').html("Thành công");
                                          //$("#auctionListDiv").html(data.Content + $("#auctionListDiv").html());
                                      }
                                  }
                              });

                          })();       
                    </script> 
                    <%} %>
                </td>
            </tr>
        </table>
            </div><!--end info-->
        </div>
        <div id='productDescriptionAddNewBuyAuction' style='background-color:#99FFCC; min-height:150px; width:100%;'>
            <textarea rows='4' cols='70' id='productDescriptionAddNewBuyAuctionInput' ></textarea>
        </div>
    </div>
    <input type='button' id='submitAddNewBuyAuction' onclick='submitAddNewBuyAuction();' value='Post'/>
    
